#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>

class Interpreter {
public:
    class Instr {
    public:
        int l, a;
        std::string f;
        Instr(){}
        Instr(std::string f, int l, int a) {
            this->f = f;
            this->l = l;
            this->a = a;
        }
    };
    std::vector<Instr> codes;
    std::vector<int> sta;
    int IP, BP, SP;
    Interpreter() {
        IP = 0;
        BP = 0;
        SP = -1;
        codes.clear();
        sta.clear();
    }
    void writeBuf(int info) {
        SP++;
        while (SP >= sta.size()) {
            sta.push_back(0);
        }
        sta[SP] = info;
    }
    int Pop() {
        return sta[SP--];
    }
    void run(std::string name);
    void oneInstruction();
    void OPRFunc(int a);
};

void Interpreter::run(std::string name) {
    std::ifstream in(name);
    Instr x;
    for (int i = 0; i < 3; i++) sta.push_back(0);

    while (in >> x.f >> x.l >> x.a) codes.push_back(x);

    while (1) {
        oneInstruction();
        // std::cout << IP << std::endl;
        if (IP == 0) return;
    }
}

void Interpreter::oneInstruction() {
    Instr nowIR(codes[IP].f, codes[IP].l, codes[IP].a);
    int point;
    if (nowIR.f == std::string("LIT")) {
        writeBuf(nowIR.a);
    } else if (nowIR.f == std::string("LOD")) {
        point = BP;
        for ( ; nowIR.l != 0; ) {
            point = sta[point];
            nowIR.l--;
        }
        auto temp = point + nowIR.a;
        writeBuf(sta[temp]);
    } else if (nowIR.f == std::string("STO")) {
        point = BP;
        for ( ; nowIR.l != 0; ) {
            point = sta[point];
            nowIR.l--;
        }
        int first = Pop();
        auto temp = point + nowIR.a;
        sta[temp] = first;
    } else if (nowIR.f == std::string("CAL")) {
        point = BP;
        for ( ; nowIR.l != 0; ) {
            point = sta[point];
            nowIR.l--;
        }
        writeBuf(point);
        writeBuf(BP);
        writeBuf(IP);
        SP -= 3;
        BP = SP + 1;
        IP = nowIR.a - 1;
    } else if (nowIR.f == std::string("INT")) {
        SP += nowIR.a;
    } else if (nowIR.f == std::string("JMP")) {
        IP = nowIR.a - 1;
    } else if (nowIR.f == std::string("JPC") && sta[SP--] == 0) {
        IP = nowIR.a - 1;
    } else if (nowIR.f == std::string("OPR")) {
        OPRFunc(nowIR.a);
    }
    IP++;
}

void Interpreter::OPRFunc(int a) {
    int first ; 
    if ( a == 0 ) {
        SP = BP - 1;
        IP = sta[SP + 3];
        BP = sta[SP + 2];
        if (!IP) IP = -1;
    }
    if ( a == 1 ) {
        sta[SP] %= 2;
    }
    if ( a == 2 ) {
        first = sta[SP];
        SP--;
        sta[SP] = (int)(sta[SP] == first);
    }
    if ( a == 3 ) {
        first = sta[SP];
        SP--;
        sta[SP] = (int)(sta[SP] != first);
    }
    if ( a == 4 ) {
        first = sta[SP];
        SP--;
        sta[SP] = (int)(sta[SP] < first);
    }
    if ( a == 5 ) {
        first = sta[SP];
        SP--;
        sta[SP] = (int)(sta[SP] <= first);
    }
    if ( a == 6 ) {
        first = sta[SP];
        SP--;
        sta[SP] = (int)(sta[SP] > first);
    }
    if ( a == 7 ) {
        first = sta[SP];
        SP--;
        sta[SP] = (int)(sta[SP] >= first);
    }
    if ( a == 8 ) {
        sta[SP] = -sta[SP];
    }
    if ( a == 9 ) {
        first = sta[SP];
        SP--;
        sta[SP] += first;
    }
    if ( a == 10 ) {
        first = sta[SP];
        SP--;
        sta[SP] -= first;
    }
    if ( a == 11 ) {
        first = sta[SP];
        SP--;
        sta[SP] *= first;
    }
    if ( a == 12 ) {
        first = sta[SP];
        SP--;
        sta[SP] /= first;
    }
    if ( a == 13 ) {
        int x;
        std::cin >> x;
        SP++;
        while (SP >= sta.size()) {
            sta.push_back(0);
        }
        sta[SP] = x;
    }
    if ( a == 14 ) {
        first = sta[SP--];
        std::cout << first << std::endl;
    }
}


int main() {
    std::string name = "program.code";
    Interpreter test;
    test.run(name);
    return 0;
}